From 541300d74abd65ed9c729b707b02b2d983e3b670 Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Fri, 13 Oct 2017 19:25:01 +0200 Subject: [PATCH] babl: always end strncpy strings with NUL The function strncpy(3) does not guarantee to end the destination string with NUL character if not enough space was available. This could happen on systems which allow paths which are longer than 4096 characters. Signed-off-by: Tobias Stoeckmann --- babl/babl-cache.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/babl/babl-cache.c b/babl/babl-cache.c index fa3f387..4954e4b 100644 --- a/babl/babl-cache.c +++ b/babl/babl-cache.c @@ -37,6 +37,7 @@ mk_ancestry_iter (const char *path) { char copy[4096]; strncpy (copy, path, 4096); + copy[sizeof (copy) - 1] = '\0'; if (strrchr (copy, '/')) { *strrchr (copy, '/') = '\0'; @@ -63,6 +64,7 @@ mk_ancestry (const char *path) { char copy[4096]; strncpy (copy, path, 4096); + copy[sizeof (copy) - 1] = '\0'; #ifdef _WIN32 for (char *c = copy; *c; c++) if (*c == '\\') @@ -77,6 +79,7 @@ static const char *fish_cache_path (void) static char path[4096]; strncpy (path, FALLBACK_CACHE_PATH, 4096); + path[sizeof (path) - 1] = '\0'; #ifndef _WIN32 if (getenv ("XDG_CACHE_HOME")) sprintf (path, "%s/babl/babl-fishes", getenv("XDG_CACHE_HOME")); -- 2.30.2